<%--
  Created by IntelliJ IDEA.
  User: 86158
  Date: 2020/7/28
  Time: 20:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <!--注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的-->
    <style>
        .client-input {
            width: 80%;
        }

        #save-client {
            margin-top: 15px;
        }
    </style>
</head>
<body>

<form id="save-client" class="layui-form" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">CID</label>
        <div class="layui-input-block">
            <input name="cid" class="layui-input client-input" type="text"
                value="${customer.cid}"   autocomplete="off" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户姓名</label>
        <div class="layui-input-block">
            <input name="cusername" class="layui-input client-input" type="text" placeholder="请输入用户名" autocomplete="off"
                   value="${customer.cusername}"    lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input name="cpassword" class="layui-input client-input" type="password"
                   value="${customer.cpassword}"   autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">公司名称</label>
        <div class="layui-input-block">
            <input name="cnickname" class="layui-input client-input" type="text" placeholder="请输入公司名称" autocomplete="off"
                   value="${customer.cnickname}"  lay-verify="required" lay-reqText="公司名称不能为空。">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账户金额</label>
        <div class="layui-input-block">
            <input name="cmoney" class="layui-input client-input" type="number" placeholder="请输入账户金额" autocomplete="off"
                   value="${customer.cmoney}"    lay-verify="money">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">公司地址</label>
        <div class="layui-input-block">
            <input name="caddress" class="layui-input client-input" type="text" placeholder="请输入公司地址" autocomplete="off"
                   value="${customer.caddress}"    lay-verify="required" lay-reqText="公司地址不能为空">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <input name="cstate" title="正常" type="radio" checked="" value="1">
            <input name="cstate" title="停用" type="radio" value="0">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="save-btn" class="layui-btn" type="submit" lay-filter="demo1" lay-submit="">立即提交</button>
            <button class="layui-btn layui-btn-primary" type="reset">重置</button>
        </div>
    </div>
</form>

<script src="https://cdn.bootcdn.net/ajax/libs/layui/2.5.6/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'jquery', 'layer'], function () {
        var form = layui.form
            , $ = layui.jquery
            , layer = layui.layer
        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '账号至少得5个字符';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , money: function (value) {
                if (value < 0)
                    return '账户金额只能为正数。';
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log(data.field);

            $.post("/BYSSM_war_exploded/updateCustomer", {
                cid:data.field.cid,
                cusername:data.field.cusername,
                cpassword:data.field.cpassword,
                cnickname:data.field.cnickname,
                cmoney:data.field.cmoney,
                caddress:data.field.caddress,
                cstate:data.field.cstate
            }, function (res) {
                if (res == "success") {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    setTimeout(function () { parent.layer.close(index) }, 100);//延迟
                }
            });
            return false;
        });
    });
</script>

</body>
</html>